import java.util.*;
public class Test2 {
    //查找两个字符串中最长的字串
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String str1 = scanner.nextLine();
            String str2 = scanner.nextLine();
            if (str1.length() <= str2.length()) {
                findSon(str1, str2);
            } else {
                findSon(str2, str1);
            }
        }
    }

    private static void findSon(String str1, String str2) {
        String result = "";
        for (int i = 1; i < str1.length(); i++) {
            StringBuffer stringBuffer = new StringBuffer();
            for (int j = i - 1; j < str1.length(); j++) {
                if (str2.contains(stringBuffer.append(str1.charAt(j)))) {
                    if (result.length() <= stringBuffer.length()) {
                        result = stringBuffer.toString();
                    }
                }
            }
        }
        System.out.println(result);
    }
}
